Skip to content

[wip] js2py to quickjs#38473

Open
derrickaw wants to merge 9 commits into
apache:masterfrom
derrickaw:20260512_js2py2wasmer
Open

[wip] js2py to quickjs#38473
derrickaw wants to merge 9 commits into
apache:masterfrom
derrickaw:20260512_js2py2wasmer

Conversation

@derrickaw
Copy link
Copy Markdown
Collaborator

  1. Try converting js2py to quickjs

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@derrickaw
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the js2py library with quickjs-ng for executing JavaScript UDFs in Beam YAML, addressing compatibility issues with Python 3.12. The implementation introduces a _JsWrapper class that utilizes thread-local caching for JavaScript functions and handles data transfer via JSON. Feedback includes suggestions to move the thread-local cache to the module level for better idiomaticity, removing a redundant local import of quickjs, and improving the regex used to identify JavaScript function names to support async declarations.

Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
@derrickaw derrickaw force-pushed the 20260512_js2py2wasmer branch from ebf6880 to 9b29dc3 Compare May 13, 2026 13:47
@derrickaw
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the js2py library with quickjs-ng for executing JavaScript UDFs within Beam YAML. Key changes include the introduction of a _JsWrapper class and a thread-local cache for JavaScript functions. Feedback focuses on potential regressions and performance issues caused by using JSON serialization for data transfer, fragility in the JavaScript variable unpacking logic for non-standard field names, and a restrictive regex for identifying function names in callables.

Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
@derrickaw derrickaw force-pushed the 20260512_js2py2wasmer branch from 74269ed to f4217b0 Compare May 14, 2026 18:50
derrickaw added 5 commits May 15, 2026 13:06
fix SomeTransform picklability in readme_test.py

fix lint

address gemini comments
@derrickaw derrickaw force-pushed the 20260512_js2py2wasmer branch from f4217b0 to 102cc4f Compare May 15, 2026 13:07
@derrickaw
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the js2py library with quickjs-ng for executing JavaScript UDFs in Beam YAML. Key changes include the introduction of a thread-local cache for compiled JS functions and expanded support for bytes, datetime, and Decimal types during Python-to-JS conversion. Feedback was provided regarding potential data corruption when decoding bytes with replacement characters and precision loss when casting Decimal to float. Additionally, the regex-based approach for extracting function names from JS callables is noted as being too restrictive for arrow functions, with a more robust wrapping approach suggested.

Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
@derrickaw derrickaw mentioned this pull request May 22, 2026
3 tasks
@derrickaw derrickaw marked this pull request as ready for review May 22, 2026 15:43
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request migrates the JavaScript execution engine in Apache Beam's YAML module from js2py to quickjs-ng. This change addresses compatibility issues with newer Python versions and enhances the robustness of JavaScript UDFs by adding better type coercion and improved function caching mechanisms.

Highlights

  • Dependency Migration: Replaced the deprecated js2py library with quickjs-ng to improve JavaScript execution capabilities within Apache Beam YAML pipelines.
  • Enhanced Type Support: Added support for handling non-serializable types like bytes, datetime, and Decimal by converting them to JavaScript-compatible formats.
  • Improved UDF Execution: Introduced a thread-local cache for JavaScript functions and a new wrapper class to handle UDF execution more efficiently.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the js2py library with quickjs-ng for executing JavaScript UDFs in Beam YAML, enabling support for Python 3.12. The changes include a new _JsFunctionWrapper class using thread-local storage for caching JS functions, updated type conversion logic in py_value_to_js_dict, and the removal of the js2py-specific object wrapping logic. Feedback highlights several potential issues: converting date/time objects to ISO strings is a breaking change for UDFs expecting JS Date objects; decoding bytes as strict UTF-8 may crash pipelines with binary data; the lack of error handling around JS execution reduces debuggability; and the variable unpacking logic for JS expressions is susceptible to syntax errors from JS reserved words and incorrect substring matching.

Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
@derrickaw derrickaw marked this pull request as draft May 22, 2026 19:11
@derrickaw derrickaw marked this pull request as ready for review May 23, 2026 03:19
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the js2py library with quickjs-ng for JavaScript UDF support in Beam YAML, ensuring compatibility with Python 3.12+. The implementation introduces a thread-local cache for JavaScript functions and expands the py_value_to_js_dict utility to handle bytes, datetime, and Decimal types. Review feedback highlighted a critical API error where quickjs.Context should be used instead of the non-existent quickjs.Function in the quickjs-ng package. Additionally, improvements were suggested to avoid data corruption when handling binary data and to prevent syntax errors when concatenating user-provided JavaScript code with internal wrappers.

Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py Outdated
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py
Comment thread sdks/python/apache_beam/yaml/yaml_mapping.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant